<?php
/**
 * User: 1971229701@qq.com
 * Date: 2020/11/2/002
 * Time: 10:39
 */

namespace app\admin\logic;


use app\common\logic\BaseLogic;
use app\common\model\Admin;
use app\common\model\IndexBanner;
use app\common\validate\AdminVal;
use function Composer\Autoload\includeFile;

class BannerLogic extends BaseLogic
{

    public function listing($page_size = 10)
    {
        $where['state'] = 1;

        $r = IndexBanner::where($where)->paginate($page_size)->toArray();
        return $r;
    }

    public function create($data)
    {

        (new IndexBanner())->save($data);
        return true;
    }

    public function update($data, $methods = 'post')
    {
        if ($methods === 'get') {
            $r = IndexBanner::get($data);
        } else {
            if (empty($data['img']))
                unset($data['img']);
            $r = IndexBanner::update($data);
        }
        return $r;
    }

    public function delete($ids)
    {
        $str = trim($ids,',');
        $_arr = explode(',',$str);
        $where[] = ['id','in',$_arr];
        $r = IndexBanner::where($where)->delete();
        return $r;
    }
}